// src/http.js
import axios from 'axios';

const instance = axios.create({
  baseURL: process.env.VUE_APP_API_URL || '/api',
  timeout: 10000, // 设置请求超时时间
});

// 请求拦截器
instance.interceptors.request.use(
  config => {
    const token = localStorage.getItem('token'); // 从localStorage获取token
    if (token) {
      config.headers['Authorization'] = `Bearer ${token}`; // 在请求头中添加token
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

export default instance;
